package cn.hou.socket01._01demo;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

//服务端
public class Server {

    final static int PORT = 9527;//端口

    public static void main(String[] args) {

        ServerSocket server = null;//创建socket服务端对象
        try {
            server = new ServerSocket(PORT);
            System.out.println("服务器启动......");
            //服务器进行阻塞,如果有客户端发送请求,则新建一个线程执行客户端请求
            Socket socket = server.accept();
            new Thread(new ServerHandler(socket)).start();
        } catch (IOException e) {
            e.printStackTrace();
        } finally { //关闭连接,释放资源
            if (server != null) {
                try {
                    server.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            server = null;
        }
    }
}
